package com.rd.student.ruanjian.class3.gaochenxi.Exam;

import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class NumberTwo {
   public static void main(String[] args) {
      File file = new File("player.txt");
      LinkedList<String> list = new LinkedList<>();
      ArrayList<String> arrayList1=new ArrayList<>();
      ArrayList<String> arrayList2=new ArrayList<>();
      //首先要读取文件
      try (FileReader fileReader = new FileReader(file);) {
         char[] chars = new char[1024];
         fileReader.read(chars);//到了chars数组
         //想要chars数组转换成字符串
         fileReader.close();
         String s = new String(chars);
         String[] split = s.split("\r");
         for(int i=0;i< split.length;i++){
            list.add(split[i]);
         }

         //现在集合种有6组元素
         for(int i=0;i<list.size();i++){
            String str="";
            str=list.get(i);
            String[] split1 = str.split(",");
            arrayList1.add(split1[0]);
            arrayList1.add(split1[1]);
         }

         System.out.println("请输入球员名：");
         Scanner scanner=new Scanner(System.in);
         String s1=scanner.next();
         for(int i=0;i<arrayList1.size();i++){
            if(arrayList1.get(i).equals(s1)){
               System.out.println("此球员存在："+arrayList1.get(i)+",他所属"+arrayList2.get(i));
            }
            else{
               System.out.println("不存在该球员！");
               break;
            }
         }
      } catch (Exception e) {
         throw new RuntimeException(e);
      }
   }
}
